import logging
import traceback

from selenium.webdriver.common.by import By
from Base.Base import Base

class Role_Page(Base):

    #点击权限管理
    dianji_loc=(By.XPATH,'//*[@id="sidebar"]/div[2]/div[1]/h2')
    # 点击角色
    juese_loc = (By.XPATH, '//*[@id="sidebar"]/div[2]/div[2]/ul/li[3]/div/a')
    # 添加
    tianjia_loc = (By.XPATH, '//*[@id="navTab"]/div[2]/div[2]/div[2]/div[1]/ul/li/a/span')
    # 输入角色名称
    name_loc = (By.XPATH, '//*[@id="form"]/div[1]/p[1]/input')
    # 输入编码
    bm_loc = (By.XPATH, '//*[@id="form"]/div[1]/p[2]/input')
    # 描述
    miaoshu_loc = (By.XPATH, '//*[@id="form"]/div[1]/p[3]/textarea')
    #删除
    shanchu_loc = (By.XPATH, '//*[@id="navTab"]/div[2]/div[2]/div[2]/div[2]/div[2]/div/table/tbody/tr[1]/td[6]/div/a[4]')
    # 点击修改
    xiugai_loc = (By.XPATH, '//*[@id="navTab"]/div[2]/div[2]/div[2]/div[2]/div[2]/div/table/tbody/tr[1]/td[6]/div/a[3]')
    # 修改内容
    xiugaineir_loc = (By.XPATH, '//*[@id="form"]/div[1]/p[3]/textarea')
    # 保存
    baocun_loc = (By.XPATH, '//*[@id="form"]/div[2]/ul/li[1]/div/div/button')
    #取消保存
    quxiao_loc=(By.CLASS_NAME,'close')
    # 点击分配菜单
    fenpei_loc = (By.XPATH, '//*[@id="navTab"]/div[2]/div[2]/div[2]/div[2]/div[2]/div/table/tbody/tr[1]/td[6]/div/a[3]')
    # 点击分配权限
    fenpeixuanxian_loc = (
    By.XPATH, '//*[@id="navTab"]/div[2]/div[2]/div[2]/div[2]/div[2]/div/table/tbody/tr[1]/td[6]/div/a[2]')
    # 切换页数
    qiehuan_loc = (By.XPATH, '//*[@id="navTab"]/div[2]/div[2]/div[2]/div[3]/div[2]/ul/li[7]/a')
    # 查看页数
    chakan_loc = (By.XPATH, '//*[@id="navTab"]/div[2]/div[2]/div[2]/div[3]/div[1]/select')
    # 窗口最大化
    zuida_loc = (By.XPATH, '/html/body/div[13]/div[1]/div/div/a[2]')
    # 窗口最小化
    zuixiao_loc = (By.XPATH, '/html/body/div[13]/div[1]/div/div/a[4]')
    # 关闭窗口
    cha_loc = (By.XPATH, '/html/body/div[13]/div[1]/div/div/a[1]')
    def dianji(self):
        '''
        权限管理
        :return:
        '''
        try:
            self.click(self.dianji_loc)
        except Exception as e:
            logging.info(traceback.format_exc(),e)

    def juese(self):
        '''
        角色管理
        :return:
        '''
        try:
            self.click(self.juese_loc)
        except Exception as e:
            logging.info(traceback.format_exc(),e)

    def tianjia(self):
        '''
        点击添加
        :return:
        '''
        try:
            self.click(self.tianjia_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def name(self,name):
        '''
        角色名称
        :return:
        '''
        try:
            self.send_keys(self.name_loc, name)
        except Exception as e:
            logging.info(traceback.format_exc(),e)

    def bm(self,bm):
        '''
        输入编码
        :return:
        '''
        try:
            self.send_keys(self.bm_loc, bm)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def miaoshu(self,miaoshu):
        '''
        输入描述
        :return:
        '''
        try:
            self.send_keys(self.miaoshu_loc, miaoshu)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def shanchu(self):
        '''
        删除
        :return:
        '''
        try:
            self.click(self.shanchu_loc)
        except Exception as e:
            logging.info(traceback.format_exc(),e)

    def xiugai(self):
        '''
        修改
        :return:
        '''
        try:
            self.click(self.xiugai_loc)
        except Exception as  e:
            logging.info(traceback.format_exc(), e)

    def xiugainr(self):
        '''
        修改内容
        :return:
        '''
        try:
            self.send_keys(self.xiugaineir_loc, '564864')
        except Exception as  e:
            logging.info(traceback.format_exc(), e)
    def baocun(self):
        '''
        点击保存
        :return:
        '''
        try:
            self.click(self.baocun_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def quxiao(self):
        '''
        取消保存
        :return:
        '''
        try:
            self.click(self.quxiao_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def fenpei(self):
        '''
        分配菜单
        :return:
        '''
        try:
            self.click(self.fenpei_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def fenpeiquanxian(self):
        '''
        分配权限
        :return:
        '''
        try:
            self.click(self.fenpeixuanxian_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def quehuan(self):
        '''
        切换页数
        :return:
        '''
        try:
            self.click(self.qiehuan_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def chakan(self):
        '''
        查看页数
        :return:
        '''
        try:
            self.click(self.chakan_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)
    def zuida(self):
        '''
        窗口最大化
        :return:
        '''
        try:
            self.click(self.zuida_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def zuixiao(self):
        '''
        窗口最小化
        :return:
        '''
        try:
            self.click(self.zuixiao_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)

    def cha(self):
        '''
        关闭窗口
        :return:
        '''
        try:
            self.click(self.cha_loc)
        except Exception as e:
            logging.info(traceback.format_exc(), e)